<?php

// +----------------------------------------------------------------------
// | v1版本接口index
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\api\v3;

use app\event\index\Share as ShareEvent;
use app\model\app\UserDynamic as UserDynamicModel;
use app\model\store\Address as AddressesModel;
use app\pay\model\PointExchange as PointExchangeModel;
use app\event\cms\Advertising as AdvertisingEvent;
use app\model\store\Good as GoodModel;
use app\model\store\StoreFloor as StoreFloorModel;
use app\model\store\StoreNav as StoreNavModel;
use think\Image as ImageThink;

class Store extends Common
{

    public function index()
    {
        $data['banners'] = AdvertisingEvent::lists(1);

//        $data['lists'] = GoodModel::with('cover')->where('status', 1)->where('type','in','0,1,2')->paginate();
//        $data['lists'] = GoodModel::with('cover')->where('status', 1)->where('type','in','0,1')->paginate();
//        $data['lists'] = GoodModel::with('cover')->where('status', 1)->where('type','in','0,1,2')->paginate();
        $data['lists'] = GoodModel::with('cover')->where('status', 1)->where('type','in','0,1')->paginate();
        $data['floors'][] = ['name'=>'海报素材','type'=>0];
        $data['floors'][] = ['name'=>'物资材料','type'=>1];
        $floor[] = ['name' => '携程酒店', 'image' => '', 'image_file' => 'cxjd'];
//        $data['category'][] = [
//            'name'=>'POS机',
//            'img'=>'',
//        ];
        return $this->successAjax($data);
    }

    public function item()
    {
        $data['info']  = GoodModel::with(['cover','image'])->where('status', 1)->where('id', $this->request->param('id'))->find();
        $data['donwload_link'] = '';
        if ($data['info']['id'] == 1)
        {
            // 生成海报

            $userDynamic = UserDynamicModel::where('user_id',  $this->user['id'])->where('shareNum',$data['info']['id'])->where('poster_id', 0)->find();
            if ($userDynamic &&  strlen($userDynamic['poster_image'])>30)
            {
                $data['donwload_link'] = $userDynamic['poster_image'];
            }
        }
        $data['address'] = AddressesModel::where('user_id', $this->user['id'])->where('status', 1)->order('is_default DESC')->find();
        $data['tips'] = '请选择您要的产品';
        return $this->successAjax($data);
    }

    public function poster()
    {
        $good = GoodModel::with('cover')->where('status', 1)->where('id', $this->request->param('id'))->find();
        $event = new ShareEvent();
        $data = $event->goodPoster($good, $this->user);
        return $this->autoAjax($data);
    }


}
